package com.qf.first.exceptions.handler;

import com.qf.first.exceptions.BaseException;
import com.qf.first.pojo.vo.RespVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常类
 */
@ControllerAdvice
@RestControllerAdvice
public class ExceptionsHandler {
    @ExceptionHandler(BaseException.class)
    @ResponseBody
    public RespVo handlerException(BaseException e){
        RespVo respVo = new RespVo();
        respVo.setCode(e.getErrorCode());
        respVo.setMsg(e.getMessage());
        return respVo;
    }
}
